import { Controller } from "../../mvc/core/Controller";
import { ITimeLimitsGiftModule } from "../../../modules/interfaces/ITimeLimitsGiftModule";
import { TimeLimitsGiftModule } from "../../../modules/TimeLimitsGiftModule";
import { TimeLimitsGiftIcon } from "../view/timeLimits/TimeLimitsGiftIcon";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SDayRechargeRewardInfo } from "../../../Message/Public/SDayRechargeRewardInfo";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { SActiveToClient } from "../../../Message/Public/SActiveToClient";
type int = number;
//class TimeLimitsGiftController
    
    export  class TimeLimitsGiftController extends Controller
    {
       

        public get module(): ITimeLimitsGiftModule
        {
            if (!this._module) 
            {
                this._module = new TimeLimitsGiftModule();
            }
            return this._module;
        }

        public get icon(): TimeLimitsGiftIcon
        {
            if (!this._icon) 
            {
                this._icon = new TimeLimitsGiftIcon();
                this._icon.updateIconInfo();
            }
            return this._icon;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.OnClickTimeLimtsIcon, this.onClickIconHandler);
            Dispatcher.addEventListener(EventName.GetTimeLimtsGifts, this.getGifts);
            NetDispatcher.addCmdListener(ServerCommand.TimeLimitsGiftInfo, this.activeOpen);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDayRechargeRewardInfoToClient, this.refreshInfo);
            return;
        }

        /* internal  */refreshInfo(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc1=arg1.messageBase as SDayRechargeRewardInfo;
            cache.timeLimitsGift.activeInfo = loc1;
            var loc3=0;
            var loc4=loc1.items;
            for(loc2 of loc4) 
            {
                if (loc2.state == 1) 
                {
                    this.icon.addHighLightEffect();
                    break;
                }
                this.icon.removeHighLightEffect();
            }
            if (this.module && !this.module.isHide) 
            {
                this.module.updateActiveInfo(loc1);
            }
            return;
        }

        /* internal  */getGifts(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.active.getGifts(loc1);
            return;
        }

        /* internal  */activeOpen(arg1: SActiveToClient): void
        {
            if (arg1.status) 
            {
                this.icon.show();
            }
            else 
            {
                this.icon.hide();
            }
            return;
        }

        /* internal  */onClickIconHandler(arg1: DataEvent): void
        {
            if (this.module.isHide) 
            {
                this.module.show();
            }
            else 
            {
                this.module.hide();
            }
            GameProxy.active.getTimeLimitsGiftInfo();
            return;
        }

        private /* var */_module: ITimeLimitsGiftModule;

        private /* var */_icon: TimeLimitsGiftIcon;
    }
